<?php

declare(strict_types=1);

namespace app\index\controller;

use app\common\TextFormat;
use think\facade\Console;
use think\facade\View;
use think\Request;

class Install
{
  /**
   * 显示资源列表
   *
   * @return \think\Response
   */
  public function index()
  {
    //
    $lock_file = app()->getRootPath() . '/install.lock';

    if (file_exists($lock_file)) {
      return redirect('/');
    }

    $output_migrate = Console::call('migrate:run');


    $output_migrate_content = $output_migrate->fetch();


    $output_seed = Console::call('seed:run');


    $output_seed_content = $output_seed->fetch();

    View::assign('migrate', TextFormat::br($output_migrate_content));
    View::assign('seed', TextFormat::br($output_seed_content));

    touch($lock_file);
    return View::fetch();
  }
}
